package io.chain.ko.handler;

import javax.servlet.http.HttpServletRequest;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

import io.chain.ko.ajax.AjaxResult;

@RestController
@ControllerAdvice
public class GlobalExceptionHandler {

	@ExceptionHandler(Exception.class)
    public ResponseEntity<AjaxResult<String>> handleUncaughtedException(HttpServletRequest request, Exception ex) {
        AjaxResult<String> ajaxResult=new AjaxResult<>();
        ajaxResult.setStatus(500L);
        ajaxResult.setException(ex.getClass().getName());
        ajaxResult.setError(ex.getMessage());
        return new ResponseEntity(ajaxResult, HttpStatus.OK);
    }
	
}
